package com.qf.service.impl;

import com.qf.dao.AccountDao;
import com.qf.service.AccountService;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

public class AccountServiceImpl implements AccountService {

    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

//    private TransactionTemplate transactionTemplate;
//
//    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
//        this.transactionTemplate = transactionTemplate;
//    }

    @Override
    public void transfer(Integer from, Integer to, Double money) {

            accountDao.decreaseMoney(from,money);
            //int i=1/0;
            accountDao.increaseMoney(to,money);
    }

//    @Override
//    public void transfer(Integer from, Integer to, Double money) {
//        //手动编程式事务
//        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//            @Override
//            protected void doInTransactionWithoutResult(TransactionStatus status) {
//                accountDao.decreaseMoney(from,money);
//                int i=1/0;
//                accountDao.increaseMoney(to,money);
//            }
//        });
//    }
}
